﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace Kopytko
{
    /// <summary>
    /// Interaction logic for ConnectionStatusIcon.xaml
    /// </summary>
    public partial class ConnectionStatusIcon : UserControl
    {


        public string Label
        {
            get { return (string)GetValue(LabelProperty); }
            set { SetValue(LabelProperty, value); }
        }

        public static readonly DependencyProperty LabelProperty =
            DependencyProperty.Register("Label", typeof(string), typeof(ConnectionStatusIcon), new UIPropertyMetadata(""));

        public ImageSource Icon
        {
            get { return (ImageSource)GetValue(IconProperty); }
            set { SetValue(IconProperty, value); }
        }

        public static readonly DependencyProperty IconProperty =
            DependencyProperty.Register("Icon", typeof(ImageSource), typeof(ConnectionStatusIcon), new UIPropertyMetadata(null));


        private ConnectionStatusEnum status;

        public ConnectionStatusEnum Status
        {
            get { return status; }
            set
            {
                status = value;

                switch (status)
                {
                    case ConnectionStatusEnum.Connected:
                        Label = "Połączony";
                        break;
                    case ConnectionStatusEnum.Disconnected:
                        Label = "Rozłączony";
                        break;
                    case ConnectionStatusEnum.Logged:
                        Label = "Zalogowany";
                        ellipse.Fill = FindResource("greenBrush") as Brush;
                        break;
                    case ConnectionStatusEnum.Failed:
                        Label = "Błąd połączenia";
                        break;
                    case ConnectionStatusEnum.Offline:
                        Label = "Offline, kliknij aby zalogować";
                        ellipse.Fill = FindResource("orangeBrush") as Brush;
                        break;
                }
            }
        }


        public ConnectionStatusIcon()
        {
            InitializeComponent();
            Status = ConnectionStatusEnum.Disconnected;
        }
    }

    public enum ConnectionStatusEnum
    {
        Disconnected,
        Connected,
        Logged,
        Failed,
        Offline,
    }
}
